package android.FiltrosJava;

import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;

public class FlipTransform extends AbstractImageBasic{
	protected int flip = 0;
	
	public void setFlipHorizontal(){
		flip = 0;			
	}
	
	public void setFlipVertical(){
		flip = 1;			
	}
	
	public BufferedImage applyFilter(BufferedImage src) {								
		int dimX = src.getWidth();
		int dimY = src.getHeight();
		WritableRaster raster_src = src.getRaster();    	   	
    	int[] imageData = new int[raster_src.getNumBands()]; 
    	int[] imageData1 = new int[raster_src.getNumBands()];
		
    	if (flip == 0){
    		for (int y = 0; y < dimY; y++){
        		for (int x = 0; x < (dimX/2.0); x++){
        			raster_src.getPixel(x,y,imageData);        			
        			raster_src.getPixel(dimX - 1 - x,y,imageData1);
        			raster_src.setPixel(x,y,imageData1);
        			raster_src.setPixel(dimX - 1 - x,y,imageData);
    			}
    		}    		
    	}else{
    		for (int x = 0; x < dimX; x++){
    			for (int y = 0; y < (dimY/2.0); y++){
    				raster_src.getPixel(x,y,imageData);
    				raster_src.getPixel(x,dimY - 1 - y,imageData1);
    				raster_src.setPixel(x,y,imageData1);
    				raster_src.setPixel(x,dimY - 1 - y,imageData);
    			}
    		}
    	}
		
		return src;		
    }

}

